package com.example.q_kang.hhh;

import android.app.Application;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.multidex.MultiDexApplication;
import android.support.v4.app.Fragment;
import android.widget.ImageView;

import com.bulong.rudeness.RudenessScreenHelper;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.example.q_kang.hhh.main.MainActivity;
import com.hjq.toast.ToastUtils;
import com.hjq.toast.style.ToastQQStyle;
import com.hjq.toast.style.ToastWhiteStyle;
import com.previewlibrary.ZoomMediaLoader;
import com.previewlibrary.loader.IZoomMediaLoader;
import com.previewlibrary.loader.MySimpleTarget;
import com.shizhefei.mvc.MVCHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.shizhefei.view.coolrefreshview.IPullHeaderFactory;
import com.shizhefei.view.coolrefreshview.PullHeader;
import com.shizhefei.view.coolrefreshview.header.DefaultHeader;
import com.shizhefei.view.coolrefreshview.header.JellyHeader;
import com.shizhefei.view.coolrefreshview.header.MaterialHeader;
import com.sskj.base.mvchelper.LoadViewFactory;
import com.tencent.bugly.crashreport.CrashReport;
import com.zxy.recovery.core.Recovery;

public class MyApplication extends MultiDexApplication {
    @Override
    public void onCreate() {
        super.onCreate();
        ToastUtils.initStyle(new ToastWhiteStyle());
        ToastUtils.init(this);
        int designWidth = 750;
        new RudenessScreenHelper(this, designWidth).activate();
        ZoomMediaLoader.getInstance().init(new IZoomMediaLoader() {
            @Override
            public void displayImage(@NonNull Fragment context, @NonNull String path, ImageView imageView, @NonNull MySimpleTarget simpleTarget) {
                Glide.with(context).asBitmap().load(path)
                        .listener(new RequestListener<Bitmap>() {
                            @Override
                            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
                                return false;
                            }

                            @Override
                            public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
                                simpleTarget.onResourceReady();
                                return false;
                            }
                        })
                        .into(imageView);
            }

            @Override
            public void displayGifImage(@NonNull Fragment context, @NonNull String path, ImageView imageView, @NonNull MySimpleTarget simpleTarget) {

            }

            @Override
            public void onStop(@NonNull Fragment context) {

            }

            @Override
            public void clearMemory(@NonNull Context c) {

            }
        });

//        Recovery.getInstance()
//                .debug(true)
//                .recoverInBackground(false)
//                .recoverStack(true)
//                .mainPage(MainActivity.class)
//                .recoverEnabled(true)
//                .callback(null)
//                .silent(false, Recovery.SilentMode.RECOVER_ACTIVITY_STACK)
//                .init(this);
        //bugly
        CrashReport.initCrashReport(this, "35071cfde0", false);

        CoolRefreshView.setPullHeaderFactory(new IPullHeaderFactory() {
            @Override
            public PullHeader made(Context context) {
                MaterialHeader commonHeader = new MaterialHeader(context);
                return commonHeader;

            }

            @Override
            public boolean isPinContent() {
                return true;
            }
        });

        MVCHelper.setLoadViewFractory(new LoadViewFactory());

    }
}
